package com.kaifamiao.N0721;

import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Scanner;

public class Node6 {
    public static void main(String[] args) {
        int[] t = new int[5];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < t.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个数");
            t[i] = sc.nextInt();
        }
        System.out.println("请选择要执行的操作，1 表示删除 2 表示添加");
        int q = sc.nextInt();
        if (q == 2) {
            System.out.println("请输入要添加的数");
            int y = sc.nextInt();
            int index = -1;
            while (!(index >= 0 && index <= 5)) {
                System.out.println("请输入想添加元素的下标(0 ~ 5)：");
                index = sc.nextInt();
            }
            int[] o = Arrays.copyOf(t, t.length + 1);
            System.arraycopy(o, index, o, index + 1, o.length - index - 1);
            o[index] = y;
            t = o;
        } else if (q == 1) {

            System.out.println("请输入想删除元素的下标(0 ~ 4)：");

            int index = sc.nextInt();

            int[] j = new int[t.length - 1];

            for (int i = 0, p = 0; i < t.length; i++) {
                if (i == index) {
                    continue;
                }
                j[p++] = t[i];
            }
            t = j;
        } else {
            System.err.println("输入错误");
        }
        for (int i = 0; i < t.length; i++) {
            System.out.println(t[i]);
        }
    }
}